home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / src / shell / nountangle < prev    next >
Text File  |  1995-02-24  |  2KB  |  68 lines

  1. #!/bin/sh
  2. #
  3. # Copyright 1991 by Norman Ramsey.  All rights reserved.
  4. # See file COPYRIGHT for more information.
  5. # set -x
  6. LIB=|LIBDIR|
  7. markup=$LIB/markup opt= arg= filters=
  8. width=72 subst='gsub("\\*/", "* /", s)' format='/* %%-%ds */'
  9.  
  10. while [ $# -gt 0 ]; do
  11.     case $1 in
  12.         -ml|-m3) format='(* %%-%ds *)' ;        subst='gsub("\\*\\)", "* )", s)' ;;
  13.         -awk|-icn|-icon)    format='# %%-%ds' ; subst=' ' ;;
  14.     -lisp|-scm)        format=';;; %%-%ds' ; subst=' ' ;;
  15.         -c++)    format='// %%-%ds' ;           subst=' ' ;;
  16.         -c)      format='/* %%-%ds */'          subst='gsub("\\*/", "* /", s)' ;;
  17.     -pascal) format='{ %%-%ds }' ;          subst='gsub("[{}]", "-", s)' ;;
  18.         -f77)    format='C %%-%ds' ;            subst=' ' ;;
  19.         -f90)    format='! %%-%ds' ;            subst=' ' ;;
  20.         -tex)    format='%%%% %%-%ds' ;         subst=' ' ;;
  21.         -L*) ;; # deliberately ignore requests for #line
  22.         -w[0-9][0-9]*)    width=`echo $1 | sed 's/^-w//'` ;;
  23.     -filter) filters=" | $filters $2 " ; shift ;;
  24.     -markup) markup="$2" ; shift ;;
  25.     -)  arg="$arg '$1'" ;;
  26.         -*) opt="$opt '$1'" ;;
  27.         *)  arg="$arg '$1'" ;;
  28.         esac
  29.     shift
  30. done
  31.  
  32. PATH="$PATH:$LIB" eval "$markup $arg $filters" |
  33. nawk 'BEGIN { line = 0; capture = 0; format=sprintf("'"$format"'",'"$width"') }
  34.  
  35. function comment(s) {
  36.     '"$subst"'
  37.     return sprintf(format,s)
  38. }
  39.  
  40. function grab(s) {
  41.   if (capture==0) print
  42.   else holding[line] = holding[line] s
  43. }
  44.    
  45. /^@end doc/ { capture = 0; holding[++line] = "" ; next }
  46. /^@begin doc/ { capture = 1; next }
  47.  
  48. /^@text /     { grab(substr($0,7)); next}
  49. /^@quote$/    { grab("[[") ; next}
  50. /^@endquote$/ { grab("]]") ; next}
  51.  
  52. /^@nl$/ { if (capture !=0 ) {
  53.             holding[++line] = ""
  54.           } else if (defn_pending != 0) {
  55.         print "@nl"
  56.             for (i=0; i<=line && holding[i] ~ /^ *$/; i++) i=i
  57.             for (; i<=line; i++) printf "@text %s\n@nl\n", comment(holding[i])
  58.             line = 0; holding[0] = ""
  59.             defn_pending = 0
  60.           } else print
  61.           next  
  62.         }
  63.  
  64. /^@defn / { holding[line] = holding[line] "<"substr($0,7)">=" # (line should be blank)
  65.             print ; defn_pending = 1 ; next }
  66. { print }' |
  67. eval "$LIB/nt $opt"
  68.